package com.cancan.cloud.shop.service.impl;

import com.cancan.cloud.shop.domain.Order;
import com.cancan.cloud.shop.domain.Product;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.Date;
import java.util.UUID;

/**
 * @program: cancan-java-share
 * @description: 定单
 * @author: czchen
 * @date: 2023-01-31 16:39:33
 */
@Service
@Slf4j
public class OrderServiceImpl {

    @Autowired
    private RestTemplate restTemplate;

//    @Override
    public Order save(Long userId, Long productId) {
        ///Product product = null;//远程获取
        Order order = new Order();
        order.setOrderNo(UUID.randomUUID().toString().replace("-", ""));
        order.setCreateTime(new Date());
        order.setUserId(userId);

        Product product = restTemplate.getForObject("http://product-server/product-server/api?id=" + userId, Product.class);

        order.setProductName(product.getName());
        order.setProductPrice(product.getPrice());
        System.out.println(product);
        System.out.println("执行保存订单操作");
        return order;
    }


}
